package com.woorigil.social.domain.provider;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class ProviderDao extends SqlMapClientDaoSupport {
	//public static final String NAMESPACE ="Provider";
	
	@Autowired
	public void setMainSqlMapClient(SqlMapClient sqlMapClient) {
		this.setSqlMapClient(sqlMapClient);
	}
	
	public int insert(Provider provider){
		return (Integer) getSqlMapClientTemplate().insert("Provider.insert", provider);
	}
	
	public int update(Provider provider){
		return (Integer) getSqlMapClientTemplate().update("Provider.update", provider);
	}
	
	public int delete(String code){
		return (Integer) getSqlMapClientTemplate().delete("Provider.delete", code);
	}
	
	public int deleteByCode(String code){
		return (Integer) getSqlMapClientTemplate().delete("Provider.delete", code);
	}
	
	public Provider select(String code){
		return (Provider) getSqlMapClientTemplate().queryForObject("Provider.select", code);
	}
	
	public Provider selectByName(String name){
		return (Provider) getSqlMapClientTemplate().queryForObject("Provider.select", name);
	}
	
	@SuppressWarnings("unchecked")
	public List<Provider> selectList(boolean isAlive) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("isAlive", isAlive);
		return getSqlMapClientTemplate().queryForList("Provider.selectList", params);
	}
}
